package logs

import (
	"strings"

	"gitee.com/lichenxin/pkg/file"
	"golang.org/x/sync/errgroup"
)

func GZLogsRange(path string, handle func(data []byte) error) error {
	values, err := file.DirFiles(path)
	if err != nil {
		return err
	}
	var eg errgroup.Group
	for _, value := range values {
		value := value
		if !strings.Contains(value, ".gz") {
			continue
		}
		eg.Go(func() error {
			return file.GZipReadLine(value, func(data []byte) error {
				return handle(data)
			})
		})
	}
	return eg.Wait()
}

